def sieve_of_eratosthenes(limit):  
    is_prime = [True] * (limit + 1)  
    is_prime[0] = is_prime[1] = False  # 0和1不是素数  

    for start in range(2, int(limit**0.5) + 1):  
        if is_prime[start]:  
            for multiple in range(start*start, limit + 1, start):  
                is_prime[multiple] = False  

    return [num for num, prime in enumerate(is_prime) if prime]  
def print_primes(limit):  
    primes = sieve_of_eratosthenes(limit)  
    for i, prime in enumerate(primes):  
        print(prime, end=' ')  
        if (i + 1) % 5 == 0:  
            print()  # 换行  
# 输出1到20000内的所有素数  
print_primes(20000)  